var express = require('express');
var router = express.Router();
const {hotelModel,roomModel,indentModel} = require('../model/lfr_model')

/* GET home page. */
router.post('/hoteladd' , (req,res)=>{
   hotelModel.create(req.body)
   
   res.send({
    code:200
   })
})

router.get('/hote' , async(req,res)=>{
  const {names}=req.query
  console.log(names)
  const na=new RegExp(names)
  data= await hotelModel.find({name:na}).populate('roomid')
  console.log(data)
  res.send(
    data
  )
})

router.post('/roomadd' , (req,res)=>{
   roomModel.create(req.body)

  res.send({
   code:200
  })
})

router.post('/indentadd' , (req,res)=>{
  indentModel.create(req.body)

 res.send({
  code:200
 })
})

router.get('/indent' , async(req,res)=>{
  data= await indentModel.find()
  res.send(
    data
  )
 })
router.get('/room' , async(req,res)=>{
 data= await roomModel.find()
 res.send(
   data
 )
})

router.get('/detail',async(req,res)=>{
  const {ids}=req.query
  data= await hotelModel.find({_id:ids}).populate('roomid')
  
  res.send(
    {
      code:200,
      data
    }
  )
})  

module.exports = router;
